package main.Q801_900;

public class Q861_870 {
    public static void main(String[] args) {
        System.out.println("Question861：翻转矩阵后的得分");
        System.out.println("Question862：");
        System.out.println("Question863：");
        System.out.println("Question864：");
        System.out.println("Question865：");
        System.out.println("Question866：");
        System.out.println("Question867：");
        System.out.println("Question868：");
        System.out.println("Question869：");
        System.out.println("Question870：");
    }
}

class Question861 {
    public int matrixScore(int[][] grid) {
        int m = grid.length, n = grid[0].length;
        int result = m * (1 << (n - 1));
        for (int j = 1; j < n; j++) {
            int nOnes = 0;
            for (int i = 0; i < m; i++) {
                if (grid[i][0] == 1) {
                    nOnes += grid[i][j];
                } else {
                    nOnes += (1 - grid[i][j]); // 如果这一行进行了行反转，则该元素的实际取值为 1 - grid[i][j]
                }
            }
            int k = Math.max(nOnes, m - nOnes);
            result += k * (1 << (n - j - 1));
        }
        return result;
    }
}